# DEMO,套接字服务端，接受客户端发来的图片并进行识别。

import camera
import baidu_api
import socket_server
import sys
import cv2

filepath = "new_test.jpg"
# 配置级联分类器
cascade = 'haarcascades/haarcascade_frontalface_alt2.xml'
# 配置token
token = '24.ebb57b5eeb8bd68404afcaf1813ecec4.2592000.1622166362.282335-24071481'
socket_server.socket_service()
img = cv2.imread(filepath)  # 读取图片
img = camera.process_image(img)# 灰度化图像
img = camera.crop_image(img, cascade)# 检测人脸并裁剪
if img is None: #检测不到人脸
    print("No face!")
    sys.exit()
cv2.imwrite(filepath, img) #保存图片
img = baidu_api.img_to_base64(filepath)
print(img)
baidu_api.face_search(img, token)
